package pl.edu.pw.perg.compinfodb.command;

import org.springframework.richclient.command.support.AbstractActionCommandExecutor;

import pl.edu.pw.perg.compinfodb.datamodel.HistoryTableModel;
import pl.edu.pw.perg.compinfodb.datamodel.IActivableModel;
import pl.edu.pw.perg.compinfodb.datamodel.IEventModificationListener;

public class SaveModelCommandExecutor extends AbstractActionCommandExecutor 
	implements IModelModificationListener, IActiveModelListener{

	private IMutableTableModel activeModel;
		
	public void modelModified(boolean modified) {
		
		setEnabled(modified);
	}

	public void setActiveModel(IActivableModel model) {
		if(model == null){
			setEnabled(false);
			return;
		}
		this.activeModel = (IMutableTableModel) model;
		modelModified(activeModel.isModified());
	}
	
	@Override
	public void execute() {
		activeModel.save();
	}


}
